<template>
  <div>
    <!-- 表格 -->
    <el-table style="width:100%" border :data="records">
      <el-table-column type="index" prop="prop" label="序号" align="center" width="80"></el-table-column>
      <el-table-column prop="skuName" label="名称" align="center" width="width"></el-table-column>      
      <el-table-column prop="skuDesc" label="描述" align="center" width="width"></el-table-column>
      <el-table-column prop="prop" label="默认图片" align="center" width="110">
        <template slot-scope="{row,$index}">
          <img :src="row.skuDefaultImg" style="height:80px;weight:80px"></img>
        </template>
      </el-table-column>
      <el-table-column prop="weight" label="重量(Kg)" align="center" width="80"></el-table-column>
      <el-table-column prop="price" label="价格(元)" align="center" width="80"></el-table-column>
      <el-table-column prop="prop" label="操作" align="center" width="width">
        <template slot-scope="{row,$index}">
          <el-button type="success" icon="el-icon-sort-down" size="mini" v-if="row.isSale==0" @click="onSale(row)"></el-button>
          <el-button type="success" icon="el-icon-sort-up" size="mini" v-else @click="cancelSale(row)"></el-button>
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="editSale(row)"></el-button>
          <el-button type="info" icon="el-icon-info" size="mini" @click="getSkuInfo(row)"></el-button>
          <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination 
      style="text-align:center" 
      :current-page="page"
      :page-sizes="[3,5,10]"
      :page-size="limit"
      layout="prev,pager,next,jumper,->,sizes,total"
      :total="total"
      @current-change="getSkuList"
      @size-change="handleSizeChange"
    >
    </el-pagination>
    
    <!-- 抽屉效果 -->
    <el-drawer
      :visible.sync="drawer"
      :direction="direction"
      :show-close="false"
      size="50%"
      >
      <el-row>
        <el-col :span="5">名称</el-col>
        <el-col :span="16">{{skuInfo.skuName}}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">描述</el-col>
        <el-col :span="16">{{skuInfo.skuDesc}}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">价格</el-col>
        <el-col :span="16">{{skuInfo.price}}元</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">平台属性</el-col>
        <el-col :span="16">
          <template>
            <el-tag type="success" style="margin-right:10px" v-for="(attr,index) in skuInfo.skuAttrValueList" :key="attr.id">{{attr.attrId}}-{{attr.valueId}}</el-tag>
          </template>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5">商品图片</el-col>
        <el-col :span="16">
          <!-- <template>
            <img :src="skuInfo.skuDefaultImg" style="height:350px;weight:350px"></img>
          </template> -->
          <el-carousel height="350px" weight="350px">
            <el-carousel-item v-for="(row,index) in skuInfo.skuImageList" :key="row">
              <img :src="row.imgUrl" style="height:350px;weight:350px"></img>
            </el-carousel-item>
          </el-carousel>
        </el-col>
      </el-row>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name:'',
  data(){
    return {
      page:1, //代表当前第几页
      limit:10,// 代表当前页面有几条数据
      records:[], // 存储sku列表的数据
      total:0,// 存储分页器一共展示的数据
      skuInfo:{},// 存储sku信息
      drawer:false,//默认抽屉效果隐藏
      direction: 'rtl',// 默认从右向左弹出
    }
  },
  mounted(){
    // 获取sku列表的方法
    this.getSkuList();
  },
  methods:{
    // 获取sku列表数据的方法
    async getSkuList(pages=1){
      this.page = pages;
      // 结构出参数
      const {page,limit} = this;
      let result = await this.$API.sku.reqSkuList(this.page,this.limit);
      if (result.code==200){
        this.total = result.data.total;
        this.records = result.data.records;
      }
    },
    // 切换展示数据条数
    handleSizeChange(limit){
      // 修改参数
      this.limit = limit;
      this.getSkuList();
    },
    // 上架
    async onSale(row){
      //
      let result = await this.$API.sku.reqSale(row.id);
      if (result.code==200){
        row.isSale = 1; 
        this.$message({type:"success",message:"上架成功"});
        
      }
    },

    // 下架
    async cancelSale(row){
      //           
      let result = await this.$API.sku.reqCancel(row.id);
      if(result.code==200){
        row.isSale = 0; 
        this.$message({type:'success',message:"下架成功"});
        
      }
    },
    editSale(row){
      this.$message("正在开发中...")
    },
    // 获取Sku详细的方法
    async getSkuInfo(sku){
      // 获取sku的数据
      let result = await this.$API.sku.reqSkuById(sku.id);
      console.log(result.data)
      if (result.code==200){
        this.skuInfo = result.data;
      };
      // 将抽屉设置为显示
      this.drawer =  true;

    }
  }
}
</script>

<style>
  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 150px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
     background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
     background-color: #d3dce6;
  }


</style>
<style scoped>
  .el-row .el-col-5{
    font-size:18px;
    text-align:right;
  }
  .el-col{
    margin:10px 10px;
  }
  >>> .el-carousel__button{
    width:10px;
    height:10px;
    background:red;
    border-radius:50%;
  }
/* 
## 深度选择器：
------------------------------------
  >>>         一般用于原生的CSS

  /deep/      一般用于less

  ::v-deep    一般用于scss
------------------------------------
## 注意：
如果父组件的样式为（scoped），还想要影响到子组件的样式，可以选择深度选择器
  深度选择器可以实现样式的穿透

## 1、scoped属性的作用 -----加上scoped的作用，只是对于当前的组件有用（样式）
  对于某个组件，如果style添加上scoped属性，给当前子组件的结构中都添加上一个data-v-xxxx自定义属性
  会发现vue是通过属性选择器，给需要添加的元素添加上样式
  类似：h3[data-v-7ba5bd90]

  2、子组件的根标签（拥有父组件当中自定义属性：一样的）,
*/
</style>